package io.renren.modules.aic.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.Assert;
import io.renren.modules.aic.entity.CtocTransactionEntity;
import io.renren.modules.aic.service.CtocTransactionService;

import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

/**
 * ctoc交易表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-03-30 15:44:17
 */
@RestController
@RequestMapping("aic/ctoctransaction")
public class CtocTransactionController {
	@Autowired
	private CtocTransactionService ctocTransactionService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("aic:ctoctransaction:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = ctocTransactionService.queryPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("aic:ctoctransaction:info")
	public R info(@PathVariable("id") Long id) {
		CtocTransactionEntity ctocTransaction = ctocTransactionService.selectById(id);

		return R.ok().put("ctocTransaction", ctocTransaction);
	}

	/**
	 * 修改
	 */
	@SysLog("申诉处理")
	@RequestMapping("/update")
	@RequiresPermissions("aic:ctoctransaction:update")
	public R update(Long[] ids, String message) {
		Assert.notNull(ids, "ids is null");
		Assert.noNullElements(ids, "参数异常[ids]");

		CtocTransactionEntity ctocTransaction = new CtocTransactionEntity();
		ctocTransaction.setAppealStatus(2);// 已处理
		ctocTransaction.setAppealDesc(message);
		ctocTransaction.setUpdateTime(new Date());
		ctocTransactionService.update(ctocTransaction, new EntityWrapper<CtocTransactionEntity>().in("id", ids));
		return R.ok();
	}

	@SysLog("确认收款")
	@RequestMapping("sellerConfirm")
	@RequiresPermissions("aic:ctoctransaction:update")
	public R sellerConfirm(Long[] ids) {
		Assert.notNull(ids, "ids is null");
		Assert.noNullElements(ids, "参数异常[ids]");
		ctocTransactionService.sellerConfirm(ids);
		return R.ok();
	}
}
